Skip to content

fix: handle missing tool arguments gracefully and prevent AI thread aborts - #2714

Merged
Datalux merged 2 commits into
Datalux:developmentfrom
SuperJaba:fix/tool-arg-fallback-and-error-handling
Oct 29, 2026
Merged

Datalux merged 2 commits into
Datalux:developmentfrom
SuperJaba:fix/tool-arg-fallback-and-error-handling

Conversation

@SuperJaba

Copy link
Copy Markdown

Summary

This PR addresses two resilience issues in tool execution during AI-driven mode:

  1. search_public_context default parameter:
    • search_public_context previously had no default for its query argument (def search_public_context(query: str)). When an LLM model invoked the tool without providing arguments or passing an empty object, Python raised an unhandled TypeError: missing 1 required positional argument: 'query'.
    • Now defaults to query: str = "" and returns a structured validation error ({"error": "Specify a public landmark, venue, brand, or event to search for."}) if omitted.
  2. Resilient _run_tool_call invocation:
    • Added a try ... except TypeError as e handler around fn(**args) in _run_tool_call so that if any model hallucinates argument names or omits required keys on any tool, the error is returned to the model as a structured tool result instead of bubbling up as an uncaught exception that abruptly aborts the entire AI worker thread with LLM error.
  3. Tests:
    • Added unit test in tests/test_web_search.py for empty/omitted queries.
    • Added unit test in tests/test_app_endpoints.py verifying _run_tool_call catches argument TypeErrors gracefully.

SuperJaba and others added 2 commits October 28, 2026 18:00
… tool

Check the model's arguments against the tool signature (inspect.bind) before
calling it, and hand back an error only when one is missing or unexpected.
Wrapping the whole call in `except TypeError` also reported a TypeError
caused by a bug inside the tool as "Invalid tool arguments", hiding the real
problem; that now propagates as before.

Add tests for an unexpected argument, a valid call, and a bug inside a tool.
@Datalux
Datalux merged commit 416a082 into Datalux:development Oct 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants